package com.glory.dmegcpda.view

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.widget.Toast
import androidx.databinding.ObservableArrayList
import com.glory.dmegcpda.R
import com.glory.dmegcpda.base.Constant
import com.glory.dmegcpda.bean.BaseRequestBean
import com.glory.dmegcpda.bean.HeaderBean
import com.glory.dmegcpda.bean.MLotListBean
import com.glory.dmegcpda.bean.NetRequestBean
import com.glory.dmegcpda.utils.TrimUtils
import com.glory.dmegcpda.viewmodel.LoginViewModel
import com.glory.mvvmnet.base.BaseActivity
import com.glory.mvvmnet.entity.ToastMessageBean
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_SharePreferencesUtils
import kotlinx.android.synthetic.main.activity_login.*
import kotlinx.android.synthetic.main.activity_material_receive.*
import kotlinx.android.synthetic.main.activity_scribing.*
import org.apache.commons.lang3.StringEscapeUtils

class LoginActivity : BaseActivity<LoginViewModel>(){

    override fun layoutId(): Int {
        return R.layout.activity_login
    }

    override fun initView(savedInstanceState: Bundle?) {
        btnLogin.setOnClickListener{

            val user = FreeApi_SharePreferencesUtils.getSharePre("SystemSet", "user", etUser.text.toString(),applicationContext)
            val password = FreeApi_SharePreferencesUtils.getSharePre("SystemSet", "password", etPassword.text.toString(),applicationContext)

//            if (user.isEmpty()&&password.isEmpty()) {
                if (etUser.text.toString().isEmpty()) {
                    viewModel.defUI.toastEvent.value = ToastMessageBean("请输入账号", false)
                    return@setOnClickListener
                }
                if (etPassword.text.toString().isEmpty()) {
                    viewModel.defUI.toastEvent.value = ToastMessageBean("请输入密码", false)
                    return@setOnClickListener
                }
                viewModel.initData(etUser.text.toString(), etPassword.text.toString())
//            }else{
//                viewModel.initData(user, password)
//            }
//            startActivity(HomeActivity::class.java)
//            finish()
        }
        ivSetting.setOnClickListener{
            startActivity(SystemSetActivity::class.java)
        }
    }

    override fun initData() {
        viewModel.defUI.callObserve.observe(this, {
            FreeApi_SharePreferencesUtils.setSharePre("SystemSet", "user", etUser.text.toString(),applicationContext)
            FreeApi_SharePreferencesUtils.setSharePre("SystemSet", "password", etPassword.text.toString(),applicationContext)

            startActivity(HomeActivity::class.java)
            finish()
        })
    }

}